<%-- 
    Document   : userlist
    Created on : Dec 24, 2011, 1:44:36 PM
    Author     : eugene
--%>

<%@page import="knowledgebase.consts.Consts"%>
<%@page import="org.springframework.security.core.authority.SimpleGrantedAuthority"%>
<%@page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Administrator Panel</title>
        <script>
            var $userCount;
            var $roleCount;
            var defaultListSize = <%=Consts.LIST_SIZE%>;
            
            $(document).ready(function() {
                $userCount = $('#userCountUI');
                $roleCount = $('#roleCountUI');
                attachTooltips();
                refreshUserCount();
                refreshRoleCount();
            })
            
            function attachTooltips(){
                $('[rel=tooltip]').tooltip();
            }
            
            function hideAllTooltips(){
                $('.in').hide();
            }
            
            function noRecordsFound(table, colspan){
                var row = $("<tr>").attr('id',"-");

                var noRecordsCell = $("<td>");
                noRecordsCell.attr('colspan',colspan);
                noRecordsCell.attr('style','text-align: center');
                noRecordsCell.html('No Records Found.');

                row.append(noRecordsCell);

                table.append(row);
            }
            
            function refreshUserCount(){
                $.ajax({
                    url: "getUserCount.html",
                    success: function(result) {
                        $userCount.html(result);
                    }
                });
            }
            
            function refreshRoleCount(){
                $.ajax({
                    url: "getRoleCount.html",
                    success: function(result) {
                        $roleCount.html(result);
                    }
                });
            }
        </script>
    </head>
    <body style="margin-left:50px;">
        <div class="row">
            <div class="span4">
                Users: <span id="userCountUI"></span><br />
                Roles: <span id="roleCountUI"></span>
            </div>
            <div class="span4">
                <h1 style="text-align: center">Administration panel <i class="icon-cog"></i><br/><small>Toolkit for administrators and managers</small></h1>
            </div>
            <div class="span4"></div>
        </div>
        <hr/>

        <div class="tabbable">
            <ul class="nav nav-tabs">
                <c:choose>
                    <c:when test="${isManagePermissions}">
                        <li class="active"><a href="#managePermissions" data-toggle="tab">Manage permissions</a></li>
                    </c:when>
                    <c:otherwise>
                        <li class="active"><a href="#manageUsers" data-toggle="tab">Manage users</a></li>
                        <li><a href="#manageRoles" data-toggle="tab">Manage roles</a></li>
                    </c:otherwise>
                </c:choose>
            </ul>

            <div class="tab-content">
                <c:choose>
                    <c:when test="${isManagePermissions}">
                        <!-- Manage Permission tab -->
                        <div class="tab-pane active" id="managePermissions">
                            <jsp:include page="manage/manage_permissions.jsp" />
                        </div>
                    </c:when>
                    <c:otherwise>
                        <!-- Manage User tab -->
                        <div class="tab-pane active" id="manageUsers">
                            <jsp:include page="manage/manage_users.jsp" />
                        </div>

                        <!-- Manage Role tab -->
                        <div class="tab-pane" id="manageRoles">
                            <jsp:include page="manage/manage_roles.jsp" />
                        </div>
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
    </body>
</html>
